
//密码显示与隐藏
$(".am-icon-eye-slash").click(function () {
    if ($(this).siblings("input").attr("type") == "text") {
        $(this).siblings("input")[0].type = "password";
        $(this).removeClass("am-icon-eye");
        $(this).addClass("am-icon-eye-slash");
    } else {
        $(this).siblings("input")[0].type = "text";
        $(this).addClass("am-icon-eye");
        $(this).removeClass("am-icon-eye-slash");
    }
});
// 在键盘按下并释放及提交后验证提交表单
$("#signForm").validate({
    errorPlacement: function (error, element) {
        // Append error within linked label
        $(element)
            .closest("form")
            .find("label[for='" + element.attr("id") + "']")
            .append(error);
    },
    errorElement: "span",
    success: function (label) {
        /*label的默认正确样式为valid，需要通过validClass来重置，否则这里添加的其他样式不能被清除*/
        label.text('').addClass('success');
    },
    rules: {
        username: {
            required: true
        },
        password: {
            required: true
        },
        captcha: {
            required: true
        }
    },
    messages: {
        username: {
            required: "请输入用户名"
        },
        password: {
            required: '请输入密码'
        },
        captcha: {
            required: '请输入验证码'
        }
    }
});

//检查大小写
/* 检测输入框的大小写是否开启 */
window.onload = function () {
    function isIE() {
        if (!!window.ActiveXObject || "ActiveXObject" in window) {
            return true;
        }
        else {
            return false;
        }
    }

    (function () {
        var inputPWD = document.getElementById('loginPasswd');
        var capital = false;
        var capitalTip = {
            elem: document.getElementById('capital'),
            toggle: function (s) {
                var sy = this.elem.style;
                var d = sy.display;
                if (s) {
                    sy.display = s;
                }
                else {
                    sy.display = d == 'none' ? '' : 'none';
                }
            }
        }
        var detectCapsLock = function (event) {
            if (capital) {
                return
            }
            ;
            var e = event || window.event;
            var keyCode = e.keyCode || e.which;
            var isShift = e.shiftKey || (keyCode == 16) || false;
            if (((keyCode >= 65 && keyCode <= 90) && !isShift) || ((keyCode >= 97 && keyCode <= 122) && isShift)) {
                capitalTip.toggle('block');
                capital = true
            }
            else {
                capitalTip.toggle('none');
            }
        }
        if (!isIE()) {
            inputPWD.onkeypress = detectCapsLock;
            inputPWD.onkeyup = function (event) {
                var e = event || window.event;
                if (e.keyCode == 20 && capital) {
                    capitalTip.toggle();
                    return false;
                }
            }
        }
    })()
}
